package com.starlink.common.annotation.client.weixin;

import com.starlink.common.annotation.client.base.Amount;
import com.starlink.common.annotation.client.base.SceneInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_4_1.shtml
 * 支付通知
 *
 * https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_3_5.shtml
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WeixinPayNotifyReq implements Serializable {
  /** 通知的唯一ID */
  private String id;
  /** 通知创建时间 */
  private String create_time;
  /** 通知类型：支付成功通知的类型为TRANSACTION.SUCCESS*/
  private String event_type;
  /** 通知数据类型：支付成功通知为encrypt-resource */
  private String resource_type;
  /** 通知数据 */
  private Resource resource;
  /** 回调摘要 */
  private String summary;

  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public static class Resource implements Serializable {
    /** 加密算法类型: 对开启结果数据进行加密的加密算法，目前只支持AEAD_AES_256_GCM */
    private String algorithm;
    /** 数据密文: Base64编码后的开启/停用结果数据密文 */
    private String ciphertext;
    /** 附加数据 */
    private String associated_data;
    /** 原始类型:原始回调类型，为transaction */
    private String original_type;
    /** 随机串: 加密使用的随机串 */
    private String nonce;
  }

  /**
   *
   {
   "transaction_id":"1217752501201407033233368018",
   "amount":{
   "payer_total":100,
   "total":100,
   "currency":"CNY",
   "payer_currency":"CNY"
   },
   "mchid":"1230000109",
   "trade_state":"SUCCESS",
   "bank_type":"CMC",
   "promotion_detail":[
   {
   "amount":100,
   "wechatpay_contribute":0,
   "coupon_id":"109519",
   "scope":"GLOBAL",
   "merchant_contribute":0,
   "name":"单品惠-6",
   "other_contribute":0,
   "currency":"CNY",
   "stock_id":"931386",
   "goods_detail":[
   {
   "goods_remark":"商品备注信息",
   "quantity":1,
   "discount_amount":1,
   "goods_id":"M1006",
   "unit_price":100
   },
   {
   "goods_remark":"商品备注信息",
   "quantity":1,
   "discount_amount":1,
   "goods_id":"M1006",
   "unit_price":100
   }
   ]
   },
   {
   "amount":100,
   "wechatpay_contribute":0,
   "coupon_id":"109519",
   "scope":"GLOBAL",
   "merchant_contribute":0,
   "name":"单品惠-6",
   "other_contribute":0,
   "currency":"CNY",
   "stock_id":"931386",
   "goods_detail":[
   {
   "goods_remark":"商品备注信息",
   "quantity":1,
   "discount_amount":1,
   "goods_id":"M1006",
   "unit_price":100
   },
   {
   "goods_remark":"商品备注信息",
   "quantity":1,
   "discount_amount":1,
   "goods_id":"M1006",
   "unit_price":100
   }
   ]
   }
   ],
   "success_time":"2018-06-08T10:34:56+08:00",
   "payer":{
   "openid":"oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"
   },
   "out_trade_no":"1217752501201407033233368018",
   "appid":"wxd678efh567hg6787",
   "trade_state_desc":"支付成功",
   "trade_type":"MICROPAY",
   "attach":"自定义数据",
   "scene_info":{
   "device_id":"013467007045764"
   }
   }
   */
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public static class DecryptResource implements Serializable {
    /** 应用ID */
    private String appid;
    /** 商户号 */
    private String mchid;
    /** 商户订单号：特殊规则：最小字符长度为6 */
    private String out_trade_no;
    /** 微信支付订单号 */
    private String transaction_id;
    /** 交易类型：JSAPI：公众号支付，NATIVE：扫码支付，APP：APP支付，MICROPAY：付款码支付，MWEB：H5支付，FACEPAY：刷脸支付 */
    private String trade_type;
    /** 交易状态：SUCCESS：支付成功，REFUND：转入退款，NOTPAY：未支付，CLOSED：已关闭，REVOKED：已撤销（付款码支付），USERPAYING：用户支付中（付款码支付），PAYERROR：支付失败(其他原因，如银行返回失败) */
    private String trade_state;
    /** 交易状态描述 */
    private String trade_state_desc;
    /** 付款银行 */
    private String bank_type;
    /** 附加数据 */
    private String attach;
    /** 支付完成时间：示例值：2018-06-08T10:34:56+08:00 */
    private String success_time;
    /** 支付者 */
    private String payer;
    /** 订单金额：是 */
    private Amount amount;
    /** 场景信息：否 */
    private SceneInfo scene_info;
  }
}
